/*
 * ContribuyentesImpuestosVerFrame.java
 *
 * Created on 24 de abril de 2008, 06:49 PM
 */
package org.morosidad.general;

import org.mybeans.Sesion;

import org.mybeans.ContribuyentesBeans;

import org.mybeans.TemporalMorosidadMensualBeans;
import java.awt.Cursor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import org.mybeans.ComerciosBeans;

import org.mybeans.MorosidadBeans;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author  avbravo
 */
public class MorosidadInformeActualizadoMorososFrame extends javax.swing.JFrame {

    String dueno;
    double morosidad;
    double recargo;
    double numeroporcentaje;
    int numeromes;
    double total;
    Sesion sesion;
    String sql;
    String tiposql;
    String idRegimen, Regimen, estatus, Mes,Telefono;
    String localTipoid;
    String localId;
    double TotalMorosidad;
    double TotalRecargo;
    double GranTotal;
    String IdCorregimiento, Corregimiento;
    ContribuyentesBeans contribuyentesBeans;
    ComerciosBeans comerciosBeans;
    TemporalMorosidadMensualBeans temporalMorosidadMensualBeans;
    MorosidadBeans morosidadBeans;
    int fila = -1;
    DefaultTableModel modelo;
    int Anio;
    int MesFecha;
    static List<String> ListaRecargoId = new ArrayList<String>();
    static List<String> ListaRecargoTipoId = new ArrayList<String>();
    static List<String> ListaRecargoIdRegimen = new ArrayList<String>();
    int NumeroRegistrosRecargosEncontrados = -1;

    public String getDueno() {
        return dueno;
    }

    public void setDueno(String dueno) {
        this.dueno = dueno;
    }

    public double getMorosidad() {
        return morosidad;
    }

    public void setMorosidad(double morosidad) {
        this.morosidad = morosidad;
    }

    public int getNumeromes() {
        return numeromes;
    }

    public void setNumeromes(int numeromes) {
        this.numeromes = numeromes;
    }

    public int getAnio() {
        return Anio;
    }

    public void setAnio(int Anio) {
        this.Anio = Anio;
    }

    public double getNumeroporcentaje() {
        return numeroporcentaje;
    }

    public void setNumeroporcentaje(double numeroporcentaje) {
        this.numeroporcentaje = numeroporcentaje;
    }

    public double getRecargo() {
        return recargo;
    }

    public void setRecargo(double recargo) {
        this.recargo = recargo;
    }

    public double getTotal() {
        return total;
    }

    public void setTotal(double total) {
        this.total = total;
    }

    /** Creates new form ContribuyentesImpuestosVerFrame */
    public MorosidadInformeActualizadoMorososFrame() {
        initComponents();
        /*
         * Fondo
         */

         
         
         

        jPanelFondo.setOpaque(false);
        setContentPane(jPanelFondo);
        /*
         * fondo
         */
        sesion = new Sesion();
        comerciosBeans = new ComerciosBeans();
        contribuyentesBeans = new ContribuyentesBeans();
        temporalMorosidadMensualBeans = new TemporalMorosidadMensualBeans();

        morosidadBeans = new MorosidadBeans();
        java.util.Calendar ca = java.util.Calendar.getInstance();
        java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());
        jFormattedTextFieldFecha.setValue(mydate);
        int year = ca.get(java.util.Calendar.YEAR);
        this.Anio = year;
        this.MesFecha = ca.get(java.util.Calendar.MONTH);
        jTextFieldAnio.setText(String.valueOf(year));

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelFondo = new javax.swing.JPanel();
        jButtonRegresar = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jTextFieldAnio = new javax.swing.JTextField();
        jButtonMostrar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jFormattedTextFieldFecha = new javax.swing.JFormattedTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButtonVistaPrevia = new javax.swing.JButton();
        jButtonImprimir = new javax.swing.JButton();
        jButtonRegresar2 = new javax.swing.JButton();
        jCheckBoxIncluirRecargo = new javax.swing.JCheckBox();
        jPanel1 = new javax.swing.JPanel();
        jTextFieldGranTotal = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jButtonVistaPrevia1 = new javax.swing.JButton();
        jButtonImprimir1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(" Morosidad Total");
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });

        jPanelFondo.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButtonRegresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar.setToolTipText("Cerrar");
        jButtonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresarActionPerformed(evt);
            }
        });

        jLabel14.setText("Año");

        jButtonMostrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/tools.png"))); // NOI18N
        jButtonMostrar.setToolTipText("Procesar");
        jButtonMostrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMostrarActionPerformed(evt);
            }
        });

        jLabel1.setText("Fecha");

        jFormattedTextFieldFecha.setEnabled(false);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Id", "Propietario", "Morosidad", "Tipo", "Telefono", "null"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Double.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jButtonVistaPrevia.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/preview.png"))); // NOI18N
        jButtonVistaPrevia.setToolTipText("Vista Previa");
        jButtonVistaPrevia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVistaPreviaActionPerformed(evt);
            }
        });

        jButtonImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/print.jpeg"))); // NOI18N
        jButtonImprimir.setToolTipText("Imprimir");
        jButtonImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonImprimirActionPerformed(evt);
            }
        });

        jButtonRegresar2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar2.setToolTipText("Regresar");
        jButtonRegresar2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresar2ActionPerformed(evt);
            }
        });

        jCheckBoxIncluirRecargo.setSelected(true);
        jCheckBoxIncluirRecargo.setText("Incluir recargo");

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jTextFieldGranTotal.setEnabled(false);

        jLabel4.setText("Gran Total");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addGap(53, 53, 53)
                .addComponent(jTextFieldGranTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldGranTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Ordenados por Corregimiento"));

        jButtonVistaPrevia1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/preview.png"))); // NOI18N
        jButtonVistaPrevia1.setToolTipText("Vista Previa");
        jButtonVistaPrevia1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVistaPrevia1ActionPerformed(evt);
            }
        });

        jButtonImprimir1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/print.jpeg"))); // NOI18N
        jButtonImprimir1.setToolTipText("Imprimir");
        jButtonImprimir1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonImprimir1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addComponent(jButtonVistaPrevia1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37)
                .addComponent(jButtonImprimir1, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(92, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonImprimir1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonVistaPrevia1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanelFondoLayout = new javax.swing.GroupLayout(jPanelFondo);
        jPanelFondo.setLayout(jPanelFondoLayout);
        jPanelFondoLayout.setHorizontalGroup(
            jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addComponent(jCheckBoxIncluirRecargo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldAnio, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButtonMostrar, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jFormattedTextFieldFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(232, 232, 232))
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 585, Short.MAX_VALUE)
                .addGap(241, 241, 241))
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(jButtonVistaPrevia, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButtonImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addComponent(jButtonRegresar2, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(198, 198, 198))
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(483, Short.MAX_VALUE))
        );
        jPanelFondoLayout.setVerticalGroup(
            jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFondoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jCheckBoxIncluirRecargo)
                            .addComponent(jLabel14)
                            .addComponent(jTextFieldAnio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jButtonMostrar))
                    .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jButtonRegresar)
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jFormattedTextFieldFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelFondoLayout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(jPanelFondoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButtonImprimir, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonVistaPrevia, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonRegresar2, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(51, 51, 51))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelFondo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanelFondo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButtonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresarActionPerformed

    dispose();
}//GEN-LAST:event_jButtonRegresarActionPerformed

private void jButtonRegresar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresar2ActionPerformed

    dispose();
}//GEN-LAST:event_jButtonRegresar2ActionPerformed

    @SuppressWarnings("static-access")
private void jButtonMostrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMostrarActionPerformed

        try {
            LimpiarTable();
            this.TotalMorosidad = 0.0;
            this.TotalRecargo = 0.0;
            this.GranTotal = 0.0;
            String SAnio = jTextFieldAnio.getText();



            if (SAnio == null || SAnio.equals("")) {
                JOptionPane.showMessageDialog(this, "No ha seleccionado el año ", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jTextFieldAnio.requestFocus();
                return;
            }
            this.Anio = Integer.parseInt(SAnio);
            /*
             * Se le suma uno al año para que genere los
             * impuestos para el siguiente año
             */

            if (this.Anio <= 2007) {
                JOptionPane.showMessageDialog(this, "Debe ingresar un año valido ", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jTextFieldAnio.requestFocus();
                return;
            }
            sesion.LimpiarTemporalMorosidadMensual();
            this.GranTotal = 0.0;
            Contribuyentes();
            Comercios();

            CargarTabla();

             DecimalFormat formateador = new DecimalFormat("#########.##");

        jTextFieldGranTotal.setText(formateador.format(this.GranTotal));
            setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));


            setCursor(null);
            // JOptionPane.showMessageDialog(this, "Proceso terminado", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_jButtonMostrarActionPerformed

private void jButtonVistaPreviaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVistaPreviaActionPerformed



    String reportSource;
    reportSource = sesion.getRutaReportes() + "MorosidadTotales.jrxml";
    String reportDest;
    reportDest = sesion.getRutaDestino() + "MorosidadTotales.html";

    Map<String, Object> params = new HashMap<String, Object>();

    try {
        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        JasperReport jasperReport =
                JasperCompileManager.compileReport(reportSource);
        params.put("P_IDMUNICIPIO", sesion.getIdmunicipio());
        params.put("P_USERNAME", sesion.getUsername());
        params.put("P_MUNICIPIO", sesion.getMunicipio());
        params.put("P_ANIO", this.Anio);



        JasperPrint jasperPrint =
                JasperFillManager.fillReport(
                jasperReport, params, sesion.con);

        JasperViewer.viewReport(jasperPrint, false);

    } catch (JRException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonVistaPreviaActionPerformed

private void jButtonImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonImprimirActionPerformed



    String reportSource;
    reportSource = sesion.getRutaReportes() + "MorosidadTotales.jrxml";
    String reportDest;
    reportDest = sesion.getRutaDestino() + "MorosidadTotales.html";

    Map<String, Object> params = new HashMap<String, Object>();

    try {
        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        JasperReport jasperReport =
                JasperCompileManager.compileReport(reportSource);
        params.put("P_IDMUNICIPIO", sesion.getIdmunicipio());
        params.put("P_USERNAME", sesion.getUsername());
        params.put("P_MUNICIPIO", sesion.getMunicipio());
        params.put("P_ANIO", this.Anio);



        JasperPrint jasperPrint =
                JasperFillManager.fillReport(
                jasperReport, params, sesion.con);

        JasperViewer.viewReport(jasperPrint, true);

    } catch (JRException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonImprimirActionPerformed

private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
    // TODO add your handling code here:
}//GEN-LAST:event_formWindowGainedFocus

private void jButtonVistaPrevia1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVistaPrevia1ActionPerformed
    // TODO add your handling code here:
     String reportSource;
    reportSource = sesion.getRutaReportes() + "MorosidadTotalCorregimientos.jrxml";
    String reportDest;
    reportDest = sesion.getRutaDestino() + "MorosidadTotalCorregimientos.html";

    Map<String, Object> params = new HashMap<String, Object>();

    try {
        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        JasperReport jasperReport =
                JasperCompileManager.compileReport(reportSource);
        params.put("P_IDMUNICIPIO", sesion.getIdmunicipio());
        params.put("P_USERNAME", sesion.getUsername());
        params.put("P_MUNICIPIO", sesion.getMunicipio());
        params.put("P_ANIO", this.Anio);



        JasperPrint jasperPrint =
                JasperFillManager.fillReport(
                jasperReport, params, sesion.con);

        JasperViewer.viewReport(jasperPrint, false);

    } catch (JRException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonVistaPrevia1ActionPerformed

private void jButtonImprimir1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonImprimir1ActionPerformed
    // TODO add your handling code here:
     String reportSource;
    reportSource = sesion.getRutaReportes() + "MorosidadTotalCorregimientos.jrxml";
    String reportDest;
    reportDest = sesion.getRutaDestino() + "MorosidadTotalCorregimientos.html";

    Map<String, Object> params = new HashMap<String, Object>();

    try {
        if (sesion.Conectar() == false) {
            JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        JasperReport jasperReport =
                JasperCompileManager.compileReport(reportSource);
        params.put("P_IDMUNICIPIO", sesion.getIdmunicipio());
        params.put("P_USERNAME", sesion.getUsername());
        params.put("P_MUNICIPIO", sesion.getMunicipio());
        params.put("P_ANIO", this.Anio);



        JasperPrint jasperPrint =
                JasperFillManager.fillReport(
                jasperReport, params, sesion.con);

        JasperViewer.viewReport(jasperPrint, true);

    } catch (JRException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButtonImprimir1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MorosidadInformeActualizadoMorososFrame().setVisible(true);
            }
        });
    }

    private void Contribuyentes() {
        try {

            String sql;
            sql = " select contribuyentes.*, corregimients.corregimiento "
                    + " from contribuyentes, corregimients "
                    + " where contribuyentes.idmunicipio = '" + sesion.getIdmunicipio() + "' and contribuyentes.activo='si'"
                    + " and contribuyentes.IDCORREGIMIENTO = corregimients.idcorregimiento ";

            if (contribuyentesBeans.CargarListadoContribuyentes(sql) == false) {
                //no existen contribuyentes para procesar en este municipio
                return;
            }
            if (contribuyentesBeans.getNumeroRegistrosLista() == - 1) {
                //   System.out.println("No tiene registros de contribuyentes");
                return;
            }


            this.localTipoid = "contribuyentes";
            for (int i = 0; i <= contribuyentesBeans.getNumeroRegistrosLista(); i++) {
                this.localId = contribuyentesBeans.getListaCedula().get(i);
                this.dueno = contribuyentesBeans.getListaContribuyente().get(i);
                this.IdCorregimiento = contribuyentesBeans.getListaIdCorregimiento().get(i);
                this.Corregimiento = contribuyentesBeans.getListaCorregimiento().get(i);
                this.Telefono  = contribuyentesBeans.getListaTelefono().get(i);
                morosidadBeans.setAnio(Anio);
                this.Mes = sesion.getNombreMes(this.MesFecha);
                morosidadBeans.setMes(this.Mes);
                morosidadBeans.VerificarMorosidad(this.localId, "contribuyentes", true);
                if (morosidadBeans.getNumeroRegistrosLista() == -1) {
                    //JOptionPane.showMessageDialog(this, "Este contribuyente no tiene morosidad", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                    // return;
                } else {
                    CargarMorosidad();
                }



            }


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "CierreMensualContable.java\nContribuyentes()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void Comercios() {
        try {

            String sql;
            sql = " select comercios.*, corregimients.corregimiento "
                    + " from comercios, corregimients "
                    + " where comercios.idmunicipio = '" + sesion.getIdmunicipio() + "' and comercios.activo='si'"
                    + " and comercios.IDCORREGIMIENTO = corregimients.idcorregimiento ";

            if (comerciosBeans.CargarListadoComercios(sql) == false) {
                //no existen contribuyentes para procesar en este municipio
                return;
            }
            if (comerciosBeans.getNumeroRegistrosLista() == - 1) {
                //   System.out.println("No tiene registros de contribuyentes");
                return;
            }


            this.localTipoid = "comercios";
            for (int i = 0; i <= comerciosBeans.getNumeroRegistrosLista(); i++) {
                this.localId = comerciosBeans.getListaIdComercio().get(i);
                this.dueno = comerciosBeans.getListaComercio().get(i);
                this.IdCorregimiento = comerciosBeans.getListaIdCorregimiento().get(i);
                this.Corregimiento = comerciosBeans.getListaCorregimiento().get(i);
                this.Telefono  = comerciosBeans.getListaTelefono().get(i);
                morosidadBeans.setAnio(Anio);
                this.Mes = sesion.getNombreMes(this.MesFecha);
                morosidadBeans.setMes(this.Mes);
                morosidadBeans.VerificarMorosidad(this.localId, "comercios", true);
                if (morosidadBeans.getNumeroRegistrosLista() == -1) {
                    //JOptionPane.showMessageDialog(this, "Este contribuyente no tiene morosidad", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                    // return;
                } else {
                    CargarMorosidad();
                }



            }


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "CierreMensualContable.java\nContribuyentes()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    @SuppressWarnings({"static-access", "static-access", "static-access"})
    public void CargarMorosidad() {
        try {
            this.morosidad = morosidadBeans.getTotalMorosidad();
            this.total = morosidadBeans.getTotalMorosidad();
            this.idRegimen = "";
            this.Regimen = "";
            // busco si tiene recargos de ese impuesto
            this.estatus = "";
            this.GranTotal += this.morosidad;

            GuardarRegistroTablaTemporal();

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "CargarMorosidad()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    @SuppressWarnings("static-access")
    private void GuardarRegistroTablaTemporal() {
        try {
            temporalMorosidadMensualBeans.setAnio(this.Anio);
            temporalMorosidadMensualBeans.setMes("");
            temporalMorosidadMensualBeans.setId(this.localId);
            temporalMorosidadMensualBeans.setTipoId(this.localTipoid);
            temporalMorosidadMensualBeans.setPropietario(this.dueno);
            temporalMorosidadMensualBeans.setDireccion("");
            temporalMorosidadMensualBeans.setRegimen(this.Regimen);
            temporalMorosidadMensualBeans.setIdRegimen(this.idRegimen);
            temporalMorosidadMensualBeans.setMorosidad(this.morosidad);
            temporalMorosidadMensualBeans.setRecargo(this.recargo);
            temporalMorosidadMensualBeans.setTotal(this.total);
            temporalMorosidadMensualBeans.setIdMunicipio(sesion.getIdmunicipio());
            temporalMorosidadMensualBeans.setNumeroMes(this.numeromes);
            temporalMorosidadMensualBeans.setNumeroPorcentaje(this.numeroporcentaje);
            temporalMorosidadMensualBeans.setTotalMorosidad(TotalMorosidad);
            temporalMorosidadMensualBeans.setTotalRecargo(TotalRecargo);
            temporalMorosidadMensualBeans.setEstatus(estatus);
            temporalMorosidadMensualBeans.setGranTotal(GranTotal);
            temporalMorosidadMensualBeans.setPlaca("");
            temporalMorosidadMensualBeans.setIdCorregimiento(this.IdCorregimiento);
            temporalMorosidadMensualBeans.setCorregimiento(this.Corregimiento);
            temporalMorosidadMensualBeans.setTelefono(this.Telefono);
            temporalMorosidadMensualBeans.Agregar();

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "GuardarRegistroTablaTemporal()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void LimpiarTable() {
        try {
            //limpiar  el jXTable

            jTextFieldGranTotal.setText("");
            boolean control = false;
            while (control == false) {
                int n = jTable1.getRowCount();

                if (n <= 0) {
                    control = true;
                } else {
                    modelo.removeRow(0);
                }

            }//while
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "Clase: PagosContribuyentesFijosFrame.java\nLimpiarTable()\n " + ex.getMessage().toString());
        }
    }

    private void CargarTabla() {
        try {
            sql = "select temporalmorosidadmensual.* from  temporalmorosidadmensual  where idmunicipio=? and username=?";
            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            PreparedStatement psquery = sesion.con.prepareStatement(sql);
            psquery.setObject(1, sesion.getIdmunicipio());
            psquery.setObject(2, sesion.getUsername()); //username
            ResultSet rs = psquery.executeQuery();

            modelo = new DefaultTableModel();
            // Creamos las columnas.
            //  modelo.addColumn("id");
            //  modelo.addColumn("propietario");
            modelo.addColumn("id");
            modelo.addColumn("propietario");
            modelo.addColumn("morosidad");
            modelo.addColumn("tipoid");
            modelo.addColumn("telefono");
            modelo.addColumn("corregimiento");
// Bucle para cada resultado en la consulta
            while (rs.next()) {
                // Se crea un array que será una de las filas de la tabla.
                Object[] fila = new Object[6]; // Hay tres columnas en la tabla

                //    fila[0] = rs.getString("id");
                //  fila[1] = rs.getString("propietario");
                fila[0] = rs.getString("id");
                fila[1] = rs.getString("propietario");
                fila[2] = rs.getString("morosidad");
                fila[3] = rs.getString("tipoid");
                fila[4] = rs.getString("telefono");
                fila[5] = rs.getString("corregimiento");

                modelo.addRow(fila);

            }
            this.jTable1.setModel(modelo);
            jTable1.setVisible(true);

            this.jTable1.addMouseListener(new MouseAdapter() {

                public void mouseClicked(MouseEvent e) {

                    fila = jTable1.rowAtPoint(e.getPoint());
                    int columna = jTable1.columnAtPoint(e.getPoint());
                    if ((fila > -1) && (columna > -1)) {
                    }
                }
            });
            TableColumn columnIdRegimen = jTable1.getColumnModel().getColumn(0);
            columnIdRegimen.setPreferredWidth(40);
            TableColumn columnRegimen = jTable1.getColumnModel().getColumn(1);
            columnRegimen.setPreferredWidth(90);
            TableColumn columnMorosidad = jTable1.getColumnModel().getColumn(2);
            columnMorosidad.setPreferredWidth(40);
            TableColumn columnMeses = jTable1.getColumnModel().getColumn(3);
            columnMeses.setPreferredWidth(40);
            sesion.con.close();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "CargarTabla()\nError " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonImprimir;
    private javax.swing.JButton jButtonImprimir1;
    private javax.swing.JButton jButtonMostrar;
    private javax.swing.JButton jButtonRegresar;
    private javax.swing.JButton jButtonRegresar2;
    private javax.swing.JButton jButtonVistaPrevia;
    private javax.swing.JButton jButtonVistaPrevia1;
    private javax.swing.JCheckBox jCheckBoxIncluirRecargo;
    private javax.swing.JFormattedTextField jFormattedTextFieldFecha;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanelFondo;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextFieldAnio;
    private javax.swing.JTextField jTextFieldGranTotal;
    // End of variables declaration//GEN-END:variables
}
